package com.wonders.frame.common.util;

import org.springframework.data.redis.core.RedisTemplate;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * Title: RedisUtil
 * Description: 
 * Company: homeszone
 * @author 顾乘瑞
 * @date 2018年6月23日
 */
public class RedisUtil {
    public static RedisTemplate<String, Object> redisTemplate;
	
	//获取jedis实例，通过redis工具类
//	public static Jedis getJedis() {
//		return RedisPool.getJedis();
//	}
	
	public static void setKV(String key, String value) {
		redisTemplate.opsForValue().set(key, value);
	}
	public static void setKV(String key, String value, Long timeout) {
		redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.MILLISECONDS);
	}
	public static Set<String> getKeys (){
		return redisTemplate.keys("*");
	}
	public static Object getKV(String key) {
		return redisTemplate.opsForValue().get(key);
	}
	public static Map<Object, Object> hget(String key) {
		return (Map<Object, Object>)redisTemplate.opsForHash().entries(key);
	}
	public static Object hget(String key, String o1) {
		return redisTemplate.opsForHash().get(key, o1);
	}
	public static void hset(String key, Map<Object, Object> map) {
		redisTemplate.opsForHash().putAll(key, map);
	}
	public static void hset(String key, String o1, String o2) {
		redisTemplate.opsForHash().put(key, o1, o2);
	}
	public static void hdel(String key, String o1) {
		redisTemplate.opsForHash().delete(key, o1);
	}
}
